<?php
  $host_sent_mail = "/usr/sbin/sendmail";
  $host_mail      = "mail.grandhotel.vn";
  require("phplibs/PHPMailer.php");
  class MyMailUtils{
      var $femail;
      var $fName;
      var $to = array();
      var $cc = array();
      var $bcc = array();
      var $reply = array();
      var $mailer;
      /**
      * @desc Initiall Mailer
      */
      function MyMailUtils(){
          global $path2phpmailer, $host_sent_mail;
          $this->mailer = new PHPMailer();
//          $this->mailer->PluginDir = $plugindir;
          $this->mailer->Host = $host_sent_mail;
          $this->mailer->CharSet = "UTF-8";
          $this->mailer->IsHTML(true);
      }
      /**
      * @desc Add from name and from address
      */
      function addFrom($fEmail, $fName = ""){
          $this->mailer->From = $fEmail;
          $this->mailer->FromName = $fName;
      }

      /**
      * @desc Add one Contact
      */
      function addTo($email, $name){
          $this->mailer->AddAddress($email, $name);
      }
      /**
      * @desc Add an array of contact. Each contact hold the email adddress and name
      */
      function addTos($array = null){
          if (isset($array) && is_array($array)){
              foreach($array as $item){
                  $this->mailer->AddAddress($item[0], $item[1]);
              }
          }
      }
      function addCc($email, $name){
          $this->mailer->AddCC($email, $name);
      }

      function addCcs($ccs = null){
          if (isset($ccs) && is_array($ccs)){
              foreach($ccs as $item){
                  $this->addCc($item[0], $item[1]);
              }
          }
      }
      function addBcc($email, $name){
          $this->mailer->AddBCC($email, $name);
      }

      function addBccs($bccs = null){
          if (isset($bccs) && is_array($bccs)){
              foreach($bccs as $item){
                  $this->mailer->AddBCC($item[0], $item[1]);
              }
          }
      }

      function resetAll(){
          $this->mailer->ClearAllRecipients();
          $this->mailer->ClearAddresses();

      }

      function addActtach($path, $file){
          $this->mailer->AddAttachment($path, $file);
      }
      function send($subject, $content){
          $this->mailer->Subject = $subject;
          $this->mailer->Body = $content;
          $res = $this->mailer->Send();
          return $res;
      }
  }
?>
